﻿@using NRemedy.MVC.UI
@model NRemedy.WS_IncidentTopTab
@{
    
    ViewBag.Title = "事件控制台";
    //事件
    NRemedyGrid<NRemedy.WS_Incident> grid_Incident = new NRemedyGrid<NRemedy.WS_Incident>(
        new { style = "width:1000px;height:382px", id = "datagrid_incident", title = "事件" },
        new { pagination = true, fitColumns = true, singleSelect = true, toolbar = "#tb", loader = "auto_err_Loader" },
        new { onBeforeLoad = "incident_BeforeLoad" })
        .Column(m => m.RequestID, "ID", null, new { hidden = true, sortable = true, width = 200 })
        .Column(m => m.IncidentNumber, "事件单号", null, new { sortable = true, width = 200 })
        .Column(m => m.Subject, "主题", null, new { width = 200 })
        .Column(m => m.Priority, "优先级", null, new { width = 200 })
        .Column(m => m.IncidentStatus, "状态", null, new { sortable = true, width = 200 })
        .Column(m => m.OwnerTeam, "负责团队", null, new { width = 200 })
        .Column(m => m.Owner, "处理人员", null, new { width = 200 })
        .Column(m => m.FullName, "中文名", null, new { hidden = true })
        .Column(m => m.Symptom, "详情", null, new { hidden = true })
        .Qulification("(EXTERNAL($1001$)) AND (EXTERNAL($1004$))");



    //工作日志   
    NRemedyGrid<NRemedy.WS_Incident_Journal> grid_WorkLog = new NRemedyGrid<NRemedy.WS_Incident_Journal>(
        new { style = "width:630px;height:210px", id = "table_worklog" },
        new { pagination = true, fitColumns = true, singleSelect = true, border = false },
        new { onBeforeLoad = "worklog_BeforeLoad" })
        .Column(m => m.RequestID, "ID", null, new { hidden = true })
        .Column(m => m.Category, "类别", null, new { sortable = true, width = 111 })
        .Column(m => m.Subject, "主题", null, new { sortable = true, width = 111 })
        .Column(m => m.CreateBy, "提交人", null, new { width = 111 })
        .Column(m => m.CreateTime, "提交日期", null, new { width = 111 }).Qulification("EXTERNAL($1002$)");
    //工作单
    NRemedyGrid<NRemedy.WS_Task> grid_WorkOrder = new NRemedyGrid<NRemedy.WS_Task>(
        new { style = "width:950px;height:200px", id = "table_workorder" },
        new { pagination = true, fitColumns = true, singleSelect = true },
        new { onBeforeLoad = "workorder_BeforeLoad" })
        .Column(m => m.RequestID, "ID", null, new { hidden = true })
        .Column(m => m.Sequence, "工序", null, new { sortable = true, width = 90 })

        .Column(m => m.AssigneeGroup, "负责团队", null, new { width = 90 })
        .Column(m => m.Assignee, "处理人员", null, new { width = 90 })
        .Column(m => m.Priority, "优先级", null, new { width = 90 })
        .Column(m => m.tms_status, "状态", null, new { width = 90 })
        .Column(m => m.TaskName, "主题", null, new { width = 90 })
        .Column(m => m.CreatedDateTime, "创建时间", null, new { width = 90 })
        .Qulification("EXTERNAL($1003$)");


    RouteValueDictionary create = new RouteValueDictionary();
    create.Add(NRemedyUIExtension.FormModelKey, "Create");

    RouteValueDictionary detail = new RouteValueDictionary();
    detail.Add(NRemedyUIExtension.FormModelKey, "Detail");

    RouteValueDictionary search = new RouteValueDictionary();
    search.Add(NRemedyUIExtension.FormModelKey, "Search");
    
    
}
<script type="text/javascript" language="javascript">

    function incident_BeforeLoad(table, param) {
        var condition = $('#1001').val();
        if (condition != null && condition != "" && condition != undefined) {
            //alert("事件过滤" + condition);
            return true;
        }
        else {
            return false;
        }

    }
    function worklog_BeforeLoad(table, param) {
        var condition = $('#1002').val();
        if (condition != null && condition != "" && condition != undefined) {
            //alert("工作日志过滤" + condition);
            return true;
        }
        else {

            return false;
        }

    }
    function workorder_BeforeLoad(table, param) {
        var condition = $('#1003').val();
        if (condition != null && condition != "" && condition != undefined) {
            //alert("工作单过滤" + condition);
            return true;
        }
        else {

            return false;
        }

    }

    //tree的初始化
    function tree_searchInit() {
        $('#tree_search').tree({
            url: '@Url.Action("Query", "Tree", new { form = "WS_IncidentTopTab", Top = "搜索条件" })',
            method: 'post',
            onBeforeLoad: function (node, param) {
                param.qu = "'536870918'=\"WS_Incident\" AND '7'=0";
                param.fields = "536870913";

                param.text = "536870913";
            },
            dnd: false,
            onLoadSuccess: function (node, data) {
                //默认选择第一个子节点               
                var children = $(this).tree('getChildren');
                //select后默认会执行onSelect 事件
                $(this).tree('select', children[1].target);
            }
            ,
            onSelect: function (node) {
                //初始化选择框的内容               
                combox_selectInit(node);
                //$('#1000').val('').val(node.text).change();
            }

        });
    }
    //combox的初始化
    function combox_selectInit(node) {
        $('#combox_select').combobox({
            panelHeight: 'auto',
            url: '@Url.Action("Query", "Menu", new { form = "WS_IncidentTopTab", vid = 536870914, tid = 536870914 })' + "?qu='536870913'=\"" + encodeURI(node.text) + "\"",
            valueField: 'v',
            textField: 't',
            method: 'post',
            onBeforeLoad: function (param) {
                param.desc = 536870916;
            },
            onLoadSuccess: function () {
                $(this).combobox('select', $(this).combobox('getData')[0].v);
            },
            onSelect: function (record) {
                //此处过滤事件数据表的内容                 
                $('#1001').val('').val(record.desc).change();
            }
        });
    }

    //注册一些事件
    function model_register() {
        //树加载(定义的搜索)         
        tree_searchInit();
        //为date类添加一个format方法
        //yyyy 年
        //MM 月
        //dd 日
        //hh 小时
        //mm 分
        //ss 秒
        //qq 季度
        //S  毫秒
        Date.prototype.formatDate = function (format) //author: meizz
        {
            var o = {
                "M+": this.getMonth() + 1, //month
                "d+": this.getDate(),    //day
                "h+": this.getHours(),   //hour
                "m+": this.getMinutes(), //minute
                "s+": this.getSeconds(), //second
                "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
                "S": this.getMilliseconds() //millisecond
            }
            if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o) if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1,
              RegExp.$1.length == 1 ? o[k] :
                ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }
        //搜索事件
        $('#btnSearch').click(function () {
            var dts = $('#dt_start').datetimebox('getValue');
            var dte = $('#dt_end').datetimebox('getValue');
            var condition = "1=1 ";
            if (dts != null && dts != "") {
                condition = condition + ' AND \'3\'>="' + dts + '"';
            }
            if (dte != null && dte != "") {
                condition = condition + ' AND \'3\'<="' + dte + '"';
            }

            $('#1004').val('').val(condition).change();
            return false;
        });
        //清除
        $('#btnClear').click(function () {
            $('#dt_start').datetimebox('clear');
            $('#dt_end').datetimebox('clear');
            $('#1004').val('');
            return false;
        });
        //开始时间选择
        $('#dt_start').datetimebox({
            "showSeconds": true,
            formatter: function (date) {
                return date.formatDate("yyyy/MM/dd hh:mm:ss");
            }

        });
        //结束时间选择
        $('#dt_end').datetimebox({
            showSeconds: true,
            formatter: function (date) {
                return date.formatDate("yyyy/MM/dd hh:mm:ss");
            }

        });
        $('#1001').change(function () {
            $('#datagrid_incident').datagrid('reload');
            return false;
        });

        $('#1002').change(function () {
            if ($(this) != null && $(this) != "" && $(this) != undefined) {
                //alert(obj);
                $('#table_worklog').datagrid('reload');
            }
            return false;
        });
        $('#1003').change(function () {
            if ($(this) != null && $(this) != "" && $(this) != undefined) {
                $('#table_workorder').datagrid('reload');
            }
            return false;
        });

        $('#1004').change(function () {
            $('#datagrid_incident').datagrid('reload');
            return false;
        });

        //注册事件数据表的一些事件
        $('#datagrid_incident').datagrid({
            //双击行事件
            onDblClickRow: function (rowIndex, rowData) {
                window.open('@Url.Action("Form", detail)' + '/' + rowData.f536870922);
            },
            //加载数据成功事件
            onLoadSuccess: function (data) {
                //给隐藏域赋值/加载工作单和工作日志 
                if (data.rows.length > 0) {
                    $(this).datagrid('selectRow', 0);
                }

            },
            onSelect: function (rowIndex, rowData) {
                //给隐藏域赋值/加载工作单和工作日志
                var condition = "('536870934' = \"" + rowData.f536870922 + "\")";
                var condition2 = "('536870914' = \"" + rowData.f536870922 + "\")";
                $('#1002').val('').val(condition).change(); //父对象ID
                $('#1003').val('').val(condition2).change(); //父对象ID
                $('#lbl_ownerteam').text(rowData.f536870955); //负责团队
                $('#lbl_owner').text(rowData.f536870956); //处理人员
                $('#lbl_name').text(rowData.f536870937); //中文名
                $('#lbl_DetailDescription').text(rowData.f536870916); //详情

            }

        });
        $('#table_worklog').datagrid({
            pageSize: 5,
            pageList: [5, 10, 15, 20],
            //双击行事件
            onDblClickRow: function (rowIndex, rowData) {
                window.open('@Url.Action("Form", "Journal", new { formmodel = "Detail", type = "incidentjournal" })' + '/' + rowData.f1);
                //window.open('@Url.Action("JournalDetail", "Journal")' + '?RequestID=' + rowData.f1 + '&Operate=Edit');
            }
        });
        $('#table_workorder').datagrid({
            pageSize: 5,
            pageList: [5, 10, 15, 20],
            //双击行事件
            onDblClickRow: function (rowIndex, rowData) {
                //window.open('@Url.Action("TaskDetails", "Task", null)' + '?RequestID=' + rowData.f1);
                window.open('@Url.Action("Form", "Task", new { formmodel = "Detail" })' + '/' + rowData.f1);
            }
        });
    }




    function add() {
        window.open('@Url.Action("Form", create)');
    }


    function del() { //删除操作

        var selectedRow = $('#datagrid_incident').datagrid('getSelected');
        if (selectedRow == null) {
            $.messager.alert("操作提示", "请先选择要删除的事件！");
            return false;
        }
        var subject = $('#datagrid_incident').datagrid('getSelected').f536870924;

        var msg = "是否确认删除【" + subject + "】 ？";
        $.messager.confirm('确认', msg, function (row) {
            if (row) {

                //获取选中行 
                var index = $('#datagrid_incident').datagrid('getRowIndex', selectedRow);
                $.ajax({
                    url: '@Url.Action("DeleteIncident", "Incident", null)',
                    type: "POST",
                    data: { requestid: selectedRow.f1 },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert("信息", "删除失败！");
                    },
                    success: function () {
                        $.messager.alert("信息", "删除成功！");
                        $('#datagrid_incident').datagrid('deleteRow', index);
                        //                        //清除下面的信息
                        //                        $('#lbl_ownerteam').text(''); //负责团队
                        //                        $('#lbl_owner').text(''); //处理人员
                        //                        $('#lbl_name').text(''); //中文名
                        //                        $('#lbl_DetailDescription').text(''); //详情
                        //                        $('#1002').val('').change();
                        //                        $('#1003').val('').change();
                    }
                });
            }
        })
    }

    //页面加载
    window.onload = function () {

        //各组件加载-定义的搜索->显示->事件->详细信息
        model_register();

        $('#536870916').combobox({
            onLoadSuccess: function () {
                var data = $('#536870916').combobox('getData');
                $("#536870916 ").combobox('select', data[0].t);
            }

        });
    }
        
</script>
<div id="wrap" class="easyui-layout" style="width: 100%; height: 720px;">
    <div id="body_left" data-options="region:'west'" style="width: 265px;">
        <div id="accordion_search" class="easyui-panel" border="false" style="height: 400px;
            width: 263px;" title="定义的搜索">
            <ul id="tree_search">
            </ul>
            <input type="text" id="1000" style="display: none;" />
        </div>
        <div id="accordion_function" class="easyui-panel" border="false" title="功能" style="height: 200px;
            width: 263px;">
            <p style="margin-left: 10px;">
                @Html.ActionLink("新建事件", "Form", "Incident", create, null)
            </p>
            <p style="margin-left: 10px;">
                @Html.ActionLink("搜索事件", "Form", "Incident", search, null)
            </p>
        </div>
    </div>
    <div id="body_center" data-options="region:'center',border:false" style="margin-left: 15px;
        padding-left: 15px; height: 550px;">
        <div style="height: 30px;">
            <p>
                <label>
                    显示&nbsp;&nbsp;</label>
                <input class="easyui-combobox" id="combox_select" name="combox_select" />
                &nbsp;&nbsp;&nbsp; @*@Html.MenuFor(m => m.CTRIP_IncidentQuery, new RemedyMVC.Menu.Menu_Incident_Combo_Condition(), new { onLoadSuccess="", onBeforeLoad = "Combox_onBeforeLoad" }, null)*@
                @*@Html.MenuFor(m => m.CTRIP_IncidentQuery, new RemedyMVC.Menu.Menu_Incident_Combo_Condition(), new { onLoadSuccess = "Combo_Condition_onLoadSuccess" }, null)*@
                <label>
                    创建时间&nbsp;&nbsp;</label>
                <input id="dt_start" type="text" />&nbsp;&nbsp; 至&nbsp;&nbsp;
                <input id="dt_end" type="text" />&nbsp;&nbsp; &nbsp;&nbsp; <a id="btnSearch" href="#"
                    class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a> &nbsp;&nbsp;
                <a id="btnClear" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">
                    清除</a>
            </p>
        </div>
        <div id="table_show" style="margin: 5px 0px 5px 0px;">
            <div id="tb" style="height: auto">
                <a id="btn_add" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'"
                    onclick="javascript:add()">新建</a> <a id="btn_delete" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'"
                        onclick="javascript:del()">删除</a>
            </div>
            @grid_Incident.GetHtml()
            <input type="text" style="display: none;" id="1001" />
            <input type="text" style="display: none;" id="1004" />
        </div>
        <div id="mm" class="easyui-panel" style="width: 1000px; border: none;">
            <div>
                <div id="div_incident_detail" class="easyui-tabs" style="height: 285px;">
                    <div title="事件详细信息" style="padding: 20px 20px 0px 20px">
                        <div style="float: left; width: 300px;">
                            <table>
                                <tr style="height: 40px; vertical-align: top;">
                                    <td>
                                        负责团队：
                                    </td>
                                    <td>
                                        <label id="lbl_ownerteam">
                                        </label>
                                    </td>
                                </tr>
                                <tr style="height: 40px; vertical-align: top;">
                                    <td>
                                        处理人员：
                                    </td>
                                    <td>
                                        <label id="lbl_owner">
                                        </label>
                                    </td>
                                </tr>
                                <tr style="height: 40px; vertical-align: top;">
                                    <td>
                                        姓名：
                                    </td>
                                    <td>
                                        <label id="lbl_name">
                                        </label>
                                    </td>
                                </tr>
                                <tr style="height: 60px; vertical-align: top;">
                                    <td>
                                        症状：
                                    </td>
                                    <td>
                                        <textarea id="lbl_DetailDescription" readonly="readonly" rows="4" style="width: 180px;"
                                            cols="18">
                                            </textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div>
                            @grid_WorkLog.GetHtml()
                            <input type="text" id="1002" style="display: none;" />
                        </div>
                    </div>
                    <div title="工作单" style="padding: 20px; height: 100%;">
                        @grid_WorkOrder.GetHtml()
                        <input type="text" id="1003" style="display: none;" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
